﻿
Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class Control_OtherListTable_Detail
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Request.QueryString("Code").ToString.Equals("0") Then

                hidID.Value = Request.QueryString("Code")
                getLoai()
                getNgonngu()
                ShowData()
            End If
        End If
    End Sub
    Protected Sub getNgonngu()
        ddlLanguageId.Items.Clear()
        ddlLanguageId.AppendDataBoundItems = True
        ddlLanguageId.Items.Add(New ListItem("---Chọn---", ""))
        Using data As New VSEntities
            Dim p = (From q In data.Languages Select q.LanguageId, q.Name).ToList
            ddlLanguageId.DataValueField = "LanguageId"
            ddlLanguageId.DataTextField = "Name"
            ddlLanguageId.DataSource = p
            ddlLanguageId.DataBind()
            ddlLanguageId.SelectedValue = 0
        End Using
    End Sub
    Protected Sub getLoai()
        ddlTypeId.Items.Clear()
        ddlTypeId.AppendDataBoundItems = True
        ddlTypeId.Items.Add(New ListItem("---Chọn---", ""))
        Using data As New VSEntities
            Dim p = (From q In data.OtherListTableTypes Select q.Id, q.Name).ToList
            ddlTypeId.DataValueField = "Id"
            ddlTypeId.DataTextField = "Name"
            ddlTypeId.DataSource = p
            ddlTypeId.DataBind()
            ddlTypeId.SelectedValue = 0
        End Using
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p As OtherListTable = (From q In data.OtherListTables Where q.OLCode = hidID.Value Select q).SingleOrDefault
            If Not p Is Nothing Then
                txtOlcode.Text = IIf(IsNothing(p.OLCode) = True, "", p.OLCode)
                txtOtherlistname.Text = IIf(IsNothing(p.OtherListName) = True, "", p.OtherListName)
                'txtSyslist.Text = IIf(IsNothing(p.SysList) = True, "", p.SysList)
                'txtValuetype.Text = IIf(IsNothing(p.ValueType) = True, "", p.ValueType)
                txtNote.Text = IIf(IsNothing(p.Note) = True, "", p.Note)
                ddlTypeId.SelectedValue = IIf(IsNothing(p.TypeId) = True, "", p.TypeId)
                ddlLanguageId.SelectedValue = IIf(IsNothing(p.LanguageId) = True, "", p.LanguageId)
            End If
        End Using
    End Sub
#End Region

End Class
